package br.ifrn.poo.aplicacao;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Color;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JButton;
import br.ifrn.poo.controle.CrudCliente;
import br.ifrn.poo.controle.CrudVeiculo;
import br.ifrn.poo.usuario.Atendente;
import br.ifrn.poo.usuario.Cliente;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.ConvolveOp;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;

public class FormCliente {
	Aplicacao aplicacao = new Aplicacao();
	Cliente objCliente = new Cliente();
	public JFrame frame = new JFrame();
	private JTextField cpf;
	private JTextField nome;
	private JTextField endereco;
	private JTextField data_nascimento;
	private JTextField rg;

	/**
	 * @wbp.parser.entryPoint
	 */
	public void cadVeiculo(final ArrayList<Atendente> array_atendentes){
		frame.setSize(650,500);
		
		JLabel lblCadastrarCliente = new JLabel("Alterar cliente");
		lblCadastrarCliente.setForeground(new Color(0, 0, 0));
		lblCadastrarCliente.setFont(new Font("Tahoma", Font.PLAIN, 24));
		lblCadastrarCliente.setHorizontalAlignment(SwingConstants.CENTER);
		
		JLabel lblCpf = new JLabel("CPF:");
		lblCpf.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		cpf = new JTextField();
		cpf.setColumns(10);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		nome = new JTextField();
		nome.setColumns(10);
		
		JLabel lblEndereo = new JLabel("Endere\u00E7o:");
		lblEndereo.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		endereco = new JTextField();
		endereco.setColumns(10);
		
		data_nascimento = new JTextField();
		data_nascimento.setColumns(10);
		
		JLabel lblIdade = new JLabel("Data de Nascimento:");
		lblIdade.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		JLabel lblRg = new JLabel("Rg:");
		lblRg.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		rg = new JTextField();
		rg.setColumns(10);
		
		JButton btnCadastrar = new JButton("Cadastrar");
		btnCadastrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				objCliente.setCpf(cpf.getText());
				objCliente.setid_atendente(array_atendentes.get(0).getId_atendente());
				objCliente.setData_nascimento(data_nascimento.getText());
				objCliente.setNome(nome.getText());
				objCliente.setRg(rg.getText());
				objCliente.setEndereco(endereco.getText());
				CrudCliente crudCliente = new CrudCliente();
				crudCliente.cadCliente(objCliente);
				//frame.setVisible(false);
				//frame = null;
				//Main.logado(array_atendentes);
				// Limpar campos
				cpf.setText(null);
				nome.setText(null);
				endereco.setText(null);
				data_nascimento.setText(null);
				rg.setText(null);
				
			}
		});
		btnCadastrar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JButton btnVoltar = new JButton("Voltar");
		btnVoltar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frame.setVisible(false);
				frame = null;
				aplicacao.logado(array_atendentes);
			}
		});
		btnVoltar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblCadastrarCliente, GroupLayout.PREFERRED_SIZE, 633, GroupLayout.PREFERRED_SIZE)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addComponent(lblEndereo, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
										.addComponent(data_nascimento, GroupLayout.PREFERRED_SIZE, 209, GroupLayout.PREFERRED_SIZE)
										.addComponent(lblIdade))
									.addGap(43)
									.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
										.addComponent(lblRg, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
										.addComponent(rg, GroupLayout.PREFERRED_SIZE, 324, GroupLayout.PREFERRED_SIZE)))
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
									.addComponent(endereco)
									.addGroup(groupLayout.createSequentialGroup()
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
											.addComponent(lblCpf, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
											.addComponent(cpf, GroupLayout.PREFERRED_SIZE, 180, GroupLayout.PREFERRED_SIZE))
										.addGap(18)
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
											.addComponent(lblNome, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
											.addComponent(nome, GroupLayout.PREFERRED_SIZE, 381, GroupLayout.PREFERRED_SIZE))))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(71)
							.addComponent(btnCadastrar, GroupLayout.PREFERRED_SIZE, 234, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(btnVoltar, GroupLayout.PREFERRED_SIZE, 246, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(1, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblCadastrarCliente, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblCpf, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
										.addComponent(cpf, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
										.addComponent(nome, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE))
									.addGap(5))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNome, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
									.addGap(40))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(151)
							.addComponent(lblEndereo, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(endereco, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblIdade, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(data_nascimento, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblRg, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(rg, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(btnCadastrar, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnVoltar, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE))
					.addGap(31))
		);
		frame.getContentPane().setLayout(groupLayout);
		frame.setVisible(true);
	}
}
